package com.zxkj.commonpatrol.viewmodel;

import android.app.Application;

import androidx.annotation.NonNull;

import com.czy.basecommon.utils.base.BaseRepository;
import com.czy.basecommon.utils.base.BaseViewModel;
import com.czy.basecommon.utils.base.StateLiveData;
import com.zxkj.commonpatrol.model.entity.CheckPointListEntity;
import com.zxkj.commonpatrol.model.entity.PointEvent;
import com.zxkj.commonpatrol.model.entity.SelectProjectEntrity;
import com.zxkj.commonpatrol.model.response.PointPatrolDetailResponse;
import com.zxkj.commonpatrol.repoisity.CheckPointDetailRepoisity;
import com.zxkj.commonpatrol.repoisity.PatrolSetQuestRepoisity;
import com.zxkj.commonpatrol.ui.CheckPointDetailActivity;

import java.util.ArrayList;
import java.util.List;

public class CheckPointDetailViewModel extends BaseViewModel<CheckPointDetailRepoisity> {
    public StateLiveData<List<CheckPointListEntity>> data=new StateLiveData<>();
    public StateLiveData<List<PointEvent>> Datas=new StateLiveData<>();
    public  StateLiveData<String> RSName=new StateLiveData<>();
    public CheckPointDetailViewModel(@NonNull Application application) {
        super(application);
    }

     public void getData(){
        mRepository.getData(0, new BaseRepository.MyBaseDataCallBack<List<CheckPointListEntity>>() {
            @Override
            public void onDataSuccessCallBack(List<CheckPointListEntity> checkPointListEntities) {
                data.postSuccess(checkPointListEntities);

            }

            @Override
            public void onDataFailCallBack(List<CheckPointListEntity> checkPointListEntities, List<CheckPointListEntity> t1) {

            }
        });





}
//

    public  void   getDeciveEvent(String RouteInspectNo,String  PointNo,String Filter){
        mRepository.getDetailData(RouteInspectNo, PointNo, Filter, new BaseRepository.MyBaseDataCallBack() {
            @Override
            public void onDataSuccessCallBack(Object o) {
                List<PointEvent>PointList=new ArrayList<>();
                PointPatrolDetailResponse response =(PointPatrolDetailResponse)o;
                List<PointPatrolDetailResponse.PointPatrolDevice> devices = response.getDevices();
                List<PointPatrolDetailResponse.PointPatrolEvent> events = response.getEvents();
                if (response.RSName!=null){
                    RSName.postSuccess(response.RSName);
                }
                if (devices!=null){
                    for (int i = 0; i <devices.size() ; i++) {
                        PointEvent event =new PointEvent();
                        PointPatrolDetailResponse.PointPatrolDevice pointPatrolDevice = devices.get(i);
                        event.setDevices(pointPatrolDevice);
                        event.setType(1);
                        PointList.add(event);
                    }

                }
                if (events!=null){
                    for (int i = 0; i <events.size() ; i++) {
                        PointEvent event =new PointEvent();
                        PointPatrolDetailResponse.PointPatrolEvent pointPatrolEvent = events.get(i);
                        event.setEvents(pointPatrolEvent);
                        event.setType(2);
                        PointList.add(event);
                    }
                }

                Datas.postSuccess(PointList);

            }

            @Override
            public void onDataFailCallBack(Object o, Object t1) {
                Datas.postFailure(404,(String)t1);
            }
        });
    }

}
